package com.itheima.pattern.interpreter;

public class Client {
    public static void main(String[] args) {
        Context context = new Context();

        Variable a = new Variable("a");
        Variable b = new Variable("b");
        Variable c = new Variable("c");
        Variable d = new Variable("d");

        context.assign(a,10);
        context.assign(b,20);
        context.assign(c,30);
        context.assign(d,40);

        //构建抽象语法书a+b-c+d,a-c+b-d
        AbstractExpression exepression=new Plus(a,new Plus(new Minus(b,c),d));
        Plus plus = new Plus(new Minus(a, b), new Minus(c, d));
        int interpret = exepression.interpret(context);
        System.out.println(exepression+"="+interpret);

        System.out.println(plus+"="+plus.interpret(context));


    }
}
